import { MockMethod } from "vite-plugin-mock";
import Mock from "mockjs";
import baseResponse from "./baseResponse";
export default [
  {
    url: "/mock/api/login",
    method: "post",
    response: ({ body }) => {
      const usersMap = {
        admin: "admin",
        user1: "user1",
      };
      if (Object.keys(usersMap).includes(body.username)) {
        if (usersMap[body.username] === body.password) {
          return baseResponse({
            username: body.username,
            roles: body.username === "admin" ? ["admin"] : [],
            accessToken: Mock.mock("@paragraph"),
            refreshToken: Mock.mock("@paragraph"),
          });
        } else {
          return baseResponse({}, { code: -1, message: "密码错误请重试" });
        }
      } else {
        return baseResponse({}, { code: -1, message: "该用户不存在" });
      }
    },
  },
] as MockMethod[];
